package com.simonall.listen;

import java.io.IOException;
import java.util.Locale;

import com.simonall.i18n.MessageSource;
import com.simonall.utils.BusinessException;
import com.simonall.utils.PropertyLoader;

import cn.hutool.core.util.StrUtil;

/**
 * 国际化语言监听器
 * 
 * @author simonall
 */
public class I18nListener implements CustomListener {

	// 方言
	private static Locale LOCALE = Locale.getDefault();
	private static String DIALECT = LOCALE.getLanguage() + StrUtil.UNDERLINE + LOCALE.getCountry();
	private static String SUFFIX = ".properties";

	@Override
	public void mount() throws BusinessException {
		try {
			String fileName = "i18n/" + DIALECT + SUFFIX;
			MessageSource.properties = PropertyLoader.load(fileName);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
